<template>
	<view class="content">
		<view class="infoBox">
			<view class="item">
				<text class="label">姓名 ：</text>
				<input type="text" placeholder="请输入您的姓名" v-model="name" />
			</view>
			<view class="item">
				<text class="label">房 号 ：</text>
				<input type="tel" v-model="building" placeholder="栋" class="building" maxlength="2" />
				<input type="tel" v-model="floor" placeholder="楼层" class="building" maxlength="2" />
				<input type="tel" v-model="house_num" placeholder="号" class="building" maxlength="2" />
			</view>
			<view class="item">
				<text class="label">联系方式 ：</text>
				<input type="text" placeholder="请输入您的联系方式" v-model="tel" maxlength="11" />
			</view>
			<view class="item" style="border: none;">
				<text class="label">身份证号 ：</text>
				<input type="text" placeholder="请输入您的身份证号" v-model="idcard" maxlength="18" />
			</view>
		</view>
		<view class="submit" @click="submit()">
			保存
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				name: '',
				building: '',
				floor: '',
				house_num: '',
				tel: '',
				idcard: '',
			}
		},
		methods: {
			submit() {
				if (!this.name) {
					return this.$toast('请填写姓名');
				}
				if (!this.building) {
					return this.$toast('请填写栋');
				}
				if (!this.floor) {
					return this.$toast('请填写楼层');
				}
				if (!this.house_num) {
					return this.$toast('请填写号');
				}
				if (!this.tel || !(/^1[3|4|5|6|8|7|9][0-9]\d{8}$/.test(this.tel))) {
					return this.$toast('联系方式不正确');
				}
				let _IDRe18 =
					/^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
				if (!this.idcard || !_IDRe18.test(this.idcard)) {
					return this.$toast('身份证号码不正确');
				}
				this.$request.post('userOwnerSave', {
					name: this.name,
					phone: this.tel,
					building: this.building,
					floor: String(this.floor).padStart(2, '0'),
					house_num: String(this.house_num).padStart(2, '0'),
					id_card: this.idcard,
				}).then(res => {
					let state = 1;
					if (res.data.code != 10000) {
						state = 0;
						return this.$toast(res.data.message);
					}
					this.$navto.navto("/pages/owner_certification_result/owner_certification_result", {
						state: state
					})
				})
			}
		},
		computed: {
			...mapState(['token']),
		},
		onLoad() {

		}
	}
</script>
<style lang="scss" scoped>
	.building {
		width: 100rpx;
		text-align: center !important;
		border: 1rpx solid #121212;
		border-radius: 10rpx;
	}

	.submit {
		width: 670rpx;
		height: 100rpx;
		border-radius: 6rpx;
		background: #121212;
		margin-top: 120rpx;
		font-weight: 700;
		font-size: 28rpx;
		color: #FFFFFF;
		letter-spacing: 6rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: 40rpx;
	}

	.item {
		padding-top: 45rpx;
		padding-bottom: 45rpx;
		border-bottom: 1rpx solid #000;
		display: flex;
		justify-content: space-between;

		input {
			text-align: right;
			font-weight: 500;
			font-size: 28rpx;
			color: #121212;
			letter-spacing: 4rpx;
		}

		.label {
			font-weight: 700;
			font-size: 28rpx;
			color: #121212;
			letter-spacing: 4rpx;
		}
	}

	.infoBox {
		padding: 0rpx 40rpx 0rpx 40rpx;
		background-color: #fff;
		margin-top: 25rpx;
	}

	.content {
		width: 100%;
		min-height: 100vh;
		background-color: #f0f0f0;
		display: flex;
		flex-direction: column;
	}
</style>